package test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * TODO
 *
 * @author david
 * @version 1.0
 * @date 2023/3/2016:08
 */
public class FirstAndLastDayOfMonth {
    public static void main(String[] args) {
        LocalDate startDate = LocalDate.of(2021, 7, 23); // 开始日期
        LocalDate endDate = LocalDate.of(2022, 12, 31); // 结束日期
        System.out.print("alter table etl_db3.admonitor add if not exists ");
        // 遍历每个月份
        for (LocalDate date = startDate; date.isBefore(endDate.plusDays(1)); date = date.plusDays(1)) {
            LocalDate firstDayOfMonth = date; // 该月第一天
            LocalDate lastDayOfMonth = date.withDayOfMonth(date.lengthOfMonth()); // 该月最后一天
//            下载文件
//            System.out.println("ftp -v -n 66.235.132.90 << EOF  \n" +
//                    "user intlcrpglobaldev_03690986 YVGJgZoa\n" +
//                    "binary \n" +
//                    "cd /aa_export\n" +
//                    "lcd /data/ondomaintest\n" +
//                    "get New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".zip\n" +
//                    "bye\n" +
//                    "EOF\n" +
//                    "echo \"New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".zip-->下载完成\"\n\n");
//
//
//            System.out.println("echo \"开始上传文件\"\n" +
//                    "USER=sftpuser\n" +
//                    "PASSWORD=7za1OyD6XGWisDRR\n" +
//                    "IP=172.31.27.32\n" +
//                    "PORT=22\n" +
//                    "lftp -u sftpuser,7za1OyD6XGWisDRR sftp://172.31.27.32 << EOF\n" +
//                    "cd /upload/ondomaintest\n" +
//                    "put /data/ondomain/New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".zip\n" +
//                    "by\n" +
//                    "EOF"+
//                    "echo \"New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".zip-->上传完成\"\n\n");


//            解压文件并重命名文件
//            System.out.println(
//                    "unzip New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".zip\n"+
//                    "echo \"New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".zip-->解压完成\"\n"+
//                     "mv New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"-"+lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".csv   New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".csv\n"+
//                     "echo \"New_Report"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyyMMdd"))+".csv-->重命名完成\"\n\n"
//            );
//            文件补数
            System.out.print(
                    "partition(dt='"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyMMdd"))+"') location 'hdfs://nameservice1/user/vivo/admonitor/"+firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyMMdd"))+"' "
            );
        }

    }
}